package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.resource.MessageConstant;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/getUsername.do")
    public Result getUsername(Authentication authentication){
        try {
            //Authentication  获取用户信息   一定 已经认证的用户信息
            String name = authentication.getName();
            if (name==null){
                return new Result(false, MessageConstant.GET_USERNAME_FAIL);
            }
            return new Result(true,MessageConstant.GET_USERNAME_SUCCESS,name);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_USERNAME_FAIL);
        }
    }
}
